package com.ruoyi.scale.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.scale.domain.ScaleTestProject;
import com.ruoyi.scale.service.IScaleTestProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 测评项目Controller
 *
 * @author dais
 * @date 2023-09-03
 */
@RestController
@RequestMapping("/scale/project")
public class ScaleTestProjectController extends BaseController {
    @Autowired
    private IScaleTestProjectService scaleTestProjectService;

    /**
     * 查询测评项目列表
     */
    @PreAuthorize("@ss.hasPermi('scale:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScaleTestProject scaleTestProject) {
        startPage();
        List<ScaleTestProject> list = scaleTestProjectService.selectScaleTestProjectList(scaleTestProject);
        return getDataTable(list);
    }

    /**
     * 导出测评项目列表
     */
    @PreAuthorize("@ss.hasPermi('scale:project:export')")
    @Log(title = "测评项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScaleTestProject scaleTestProject) {
        List<ScaleTestProject> list = scaleTestProjectService.selectScaleTestProjectList(scaleTestProject);
        ExcelUtil<ScaleTestProject> util = new ExcelUtil<ScaleTestProject>(ScaleTestProject.class);
        util.exportExcel(response, list, "测评项目数据");
    }

    /**
     * 获取测评项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('scale:project:query')")
    @GetMapping(value = "/{testProjectId}")
    public AjaxResult getInfo(@PathVariable("testProjectId") Long testProjectId) {
        return success(scaleTestProjectService.selectScaleTestProjectByTestProjectId(testProjectId));
    }

    /**
     * 新增测评项目
     */
    @PreAuthorize("@ss.hasPermi('scale:project:add')")
    @Log(title = "测评项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScaleTestProject scaleTestProject) {
        return toAjax(scaleTestProjectService.insertScaleTestProject(scaleTestProject));
    }

    /**
     * 修改测评项目
     */
    @PreAuthorize("@ss.hasPermi('scale:project:edit')")
    @Log(title = "测评项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScaleTestProject scaleTestProject) {
        return toAjax(scaleTestProjectService.updateScaleTestProject(scaleTestProject));
    }

    /**
     * 删除测评项目
     */
    @PreAuthorize("@ss.hasPermi('scale:project:remove')")
    @Log(title = "测评项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{testProjectIds}")
    public AjaxResult remove(@PathVariable Long[] testProjectIds) {
        return toAjax(scaleTestProjectService.deleteScaleTestProjectByTestProjectIds(testProjectIds));
    }
}
